package com.cloudwise.thread;

/**
 * @author ：Teacher陈
 * @date ：Created in 2021/1/5 22:30
 * @description：
 * @modified By：
 * @version:
 */
public class LockTest {
    /**
     * @param args
     */
    public static void main(String[] args) {
        final Object lock = new Object();
        //创建两个线程
        Runnable t1= new Runnable() {

            @Override
            public void run() {
                synchronized (lock) {
                    System.out.println(1);
                    try {
                        /*Thread.sleep(3000);*/
                        lock.wait(2000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(2);
                }

            }
        };
        Runnable t2= new Runnable() {

            @Override
            public void run() {
                synchronized (lock) {
                    System.out.println(3);
                    try {
                        Thread.sleep(3000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(4);
                }

            }
        };

        new Thread(t1).start();
        new Thread(t2).start();

    }
}
